package cn.jbolt.ec.commodity;

import cn.jbolt._admin.permission.CheckPermission;
import cn.jbolt._admin.permission.PermissionKey;
import cn.jbolt.base.JBoltBaseController;
import cn.jbolt.common.model.BecRetailerCommodityType;
import com.jfinal.aop.Inject;

@CheckPermission(PermissionKey.COMMODITY_TYPE_ADMIN)
public class EcCommodityTypeAuthController extends JBoltBaseController {
    @Inject
    CommodityTypeService service;
    /**
     * commodityType管理的首页
     */
    @CheckPermission(PermissionKey.COMMODITY_TYPE_INDEX)
    public void index(){
        render("index.html");
    }

    //---------------集成-----------------
    /**
     * @author zedomi
     */

    /**
     * 指向edit页面  通过set传给前端数据
     */
@CheckPermission(PermissionKey.COMMODITY_TYPE_UPDATE)
    public void edit_Commodity_Type(){

        Integer id=getInt(0);
        if(isOk(id)){
            BecRetailerCommodityType becRetailerCommodityType=service.findById(id);
            if(becRetailerCommodityType==null){
                renderErrorPortal("分类信息不存在");
                return;
            }
            set("retailerCommodityType",becRetailerCommodityType);
            set("pid",becRetailerCommodityType.getPid());
        }
        render("edit.html");
    }

    /**
     * 获取后台分类树
     */
    public void mgrTree(){
        renderJsonData(service.get_mgrTree(getInt(0)));
    }

    /**
     * 保存新增的商品分类
     */
    @CheckPermission(PermissionKey.COMMODITY_TYOE_ADD)
    public void save_Commodity_Type(){
        renderJson(service.save_Commodity_Type(getSessionAdminUserId(),getModel(BecRetailerCommodityType.class,"commodityType")));
    }

    /**
     * 更新商品分类
     */
    @CheckPermission(PermissionKey.COMMODITY_TYPE_UPDATE)
    public void update_Commodity_Type(){
        renderJson(service.update_Commodity_Type(getSessionAdminUserId(),getModel(BecRetailerCommodityType.class,"commodityType")));
    }

    /**
     * 软删除商品分类
     */
    @CheckPermission(PermissionKey.COMMODITY_TYPE_DELETE)
    public void delete_Commodity_Type(){
        renderJson(service.delete_Commodity_Type(getSessionAdminUserId(),getInt(0)));
    }

    /**
     * 将pid传给add页面
     */
    @CheckPermission(PermissionKey.COMMODITY_TYOE_ADD)
    public void add_Commodity_Type(){
        set("pid", getInt(0,0));
        render("add.html");
    }

    /**
     * 商品页面需要使用的 筛选商品的tree
     */
    public void get_filter_tree() {
        renderJsonData(service.getMgrTree(getInt(0,0)));
    }


    /**
     * 添加商品第一步需要选择的商品分类数据源
     */
@CheckPermission({PermissionKey.COMMODITY_TYPE_INDEX, PermissionKey.COMMODITY_INDEX})
    public void selectbox() {
        renderJsonData(service.getEnableListByPid(getInt(0,0)));
    }


}
